#include "board_base.h"

#include "usart.h"
#include "ITM.h"
#include "tim.h"
#include "gpio.h"
#include "adc.h"
#include "task_main.h"
#include "bsp_uart.h"
#include "log.h"
/*-----------------------------------------------------------------------
|                                define                                 |
-----------------------------------------------------------------------*/

/*-----------------------------------------------------------------------
|                               Function                                |
-----------------------------------------------------------------------*/

/**
 * @brief 记录归零，开始测量时间
 * @param timecnt 用来记录时间的变量
 * @retval uint32_t 
 */
extern "C" void bsp_MesureTimeStart(uint32_t *timecnt)
{
    *timecnt = HAL_GetTick();
}

/**
 * @brief 测量时间
 * @param old_counter 用来记录时间的变量
 * @retval uint32_t 上次使用到这次使用的时间(ms)
 */
extern "C" uint32_t bsp_MesureTime(uint32_t *old_counter)
{
    uint32_t counter, couter_current;
    couter_current = HAL_GetTick();
    if (couter_current > *old_counter)//没有溢出
        counter = couter_current - *old_counter;
    else//发生过溢出
        counter = couter_current + 0XFFFFFFFF - *old_counter;
    *old_counter = couter_current;
    return (counter);
}

/**
 * @brief 板载资源初始化
 */
extern "C" void board_base_init(void)
{
    // DWT init
    DWT_Init();

    // GPIO初始化
    LEDx_Write(LED1, 0);

}

